//
// Copyright (c) 2011, Peter Lane
// Licensed under the Academic Free License version 3.0

package fan.swtChartWrapper;

import fan.fwt.*;
import fan.gfx.Color;
import fan.sys.*;
import org.eclipse.swtchart.ILineSeries;
import org.eclipse.swtchart.ISeries;

public class ScatterSeriesPeer extends SeriesPeer {

  public static ScatterSeriesPeer make (fan.swtChartWrapper.ScatterSeries self) throws Exception {
    ScatterSeriesPeer peer = new ScatterSeriesPeer ();
    ((Series)self).peer = peer; // override base class's peer field
    return peer;
  }

  public void setISeries (ISeries series) {
    _series = series;
    _pointFormat.peer.setILabel (_series.getLabel ());
    _xErrorBar.peer.setIErrorBar (_series.getXErrorBar ());
    _yErrorBar.peer.setIErrorBar (_series.getYErrorBar ());
    setXPoints (_xPoints);
    setYPoints (_yPoints);
    ((ILineSeries)_series).setSymbolColor (Fwt.get().color(_symbolColour));
    ((ILineSeries)_series).setSymbolType (Utility.toSwt (_symbolType));
    ((ILineSeries)_series).setSymbolSize ((int)_symbolSize);
    ((ILineSeries)_series).setLineStyle(org.eclipse.swtchart.LineStyle.NONE);
  }

  private List _xPoints;
  public List xPoints (fan.swtChartWrapper.ScatterSeries self) {
    return _xPoints;
  }
  public void xPoints (fan.swtChartWrapper.ScatterSeries self, List xPoints) {
    _xPoints = xPoints.dup ();
    if (_series != null) setXPoints(_xPoints);
  }

  private List _yPoints;
  public List yPoints (fan.swtChartWrapper.ScatterSeries self) {
    return _yPoints;
  }
  public void yPoints (fan.swtChartWrapper.ScatterSeries self, List yPoints) {
    _yPoints = yPoints.dup ();
    if (_series != null) setYPoints(_yPoints);
  }

  private Color _symbolColour = Color.gray;
  public Color symbolColor (fan.swtChartWrapper.ScatterSeries self) { return _symbolColour; }
  public void symbolColor (fan.swtChartWrapper.ScatterSeries self, Color v) {
    _symbolColour = v;
    if (_series != null) ((ILineSeries)_series).setSymbolColor (Fwt.get().color(_symbolColour));
  }  
  
  private PlotSymbolType _symbolType = PlotSymbolType.circle;
  public PlotSymbolType symbolType (fan.swtChartWrapper.ScatterSeries self) { return _symbolType; }
  public void symbolType (fan.swtChartWrapper.ScatterSeries self, PlotSymbolType v) {
    _symbolType = v;
    if (_series != null) ((ILineSeries)_series).setSymbolType (Utility.toSwt (_symbolType));
  }

  private long _symbolSize = 4;
  public long symbolSize (fan.swtChartWrapper.ScatterSeries self) { return _symbolSize; }
  public void symbolSize (fan.swtChartWrapper.ScatterSeries self, long v) {
    if (v < 0) // trap negative size
      _symbolSize = 0;
    else
      _symbolSize = v;
    if (_series != null) ((ILineSeries)_series).setSymbolSize ((int)_symbolSize);
  }

  public ISeries.SeriesType type () { return ISeries.SeriesType.LINE; }
}
